//#define DEBUG
#include <cstdio>
#include <cstring>

using namespace std;

const int maxk=200, mods=998244353;

class Matrix {
public:
  int n, m;
  long long a[maxk+1][maxk+1];

  void mul(Matrix *x, Matrix *y, int mods) {
    if (x->m!=y->n) {
      throw -1;
    }
    n = x->n, m = y->m;
    for (int i=0; i<n; i++) {
      for (int j=0; j<m; j++) {
	a[i][j] = 0;
	for (int k=0; k<x->m; k++) {
	  a[i][j] = (a[i][j]+x->a[i][k]*y->a[k][j]%mods)%mods;
	}
      }
    }
  }

  void one(int x) {
    n = m = x;
    for (int i=0; i<n; i++) {
      a[i][i] = 1;
    }
  }
};

void qpower(Matrix *a, int n, int mods) {
  static Matrix s[2], t[2];
  s[0].one(a->n);
  t[0] = *a;
  int i=0, j=0;
  for (; n>1; n/=2) {
    if (n%2) {
      j++;
      s[j%2].mul(&t[i%2], &s[(j-1)%2], mods);
    }
    i++;
    t[i%2].mul(&t[(i-1)%2], &t[(i-1)%2], mods);
  }
  a->mul(&t[i%2], &s[j%2], mods);
}

long long qpower(long long a, int n, int mods) {
  if (n==0) {
    return 1;
  }
  long long s=1;
  for (; n>1; n/=2) {
    if (n%2) {
      s = s*a%mods;
    }
    a = a*a%mods;
  }
  return s*a%mods;
}

void initMatrix(Matrix *a, int k, int *b) {
  a->n = a->m = k;
  for (int i=1; i<=k; i++) {
    a->a[i-1][0] = b[i];
    if (i<k) {
      a->a[i-1][i] = 1;
    }
  }
}

long long solve(int n, int k, int *b, long long *f) {
  if (n<=k) {
    return f[n];
  }
  static Matrix tpl;
  initMatrix(&tpl, k, b);
  qpower(&tpl, n-k, mods-1);
  long long ans=1;
  static Matrix temp[2];
  for (int i=0; i<k; i++) {
    memset(temp, 0, sizeof(temp[0]));
    temp[0].n = 1, temp[0].m = k;
    temp[0].a[0][i] = 1;
    temp[1].mul(temp, &tpl, mods-1);
    ans = ans*qpower(f[k-i], temp[1].a[0][0], mods)%mods;
  }
  return ans;
}

int main() {
  freopen("seq.in", "r", stdin);
  freopen("seq.out", "w", stdout);

  static int b[maxk+1];
  static long long f[maxk+1];
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i=1; i<=k; i++) {
    scanf("%d", b+i);
  }
  for (int i=1; i<=k; i++) {
    scanf("%lld", f+i);
  }

  printf("%lld", solve(n, k, b, f));
    
  fclose(stdin);
  fclose(stdout);
  return 0;
}
